<?php if (!defined('CORE_DIR')) die('Wrong entry point!');

/* 
 * Copyright 2010 Anton Muraviev a.k.a kuromaisu
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */

Aero::define('LocalisationLibarySpecification', AS_SINGLETON);

/*
 * LocalisationLibarySpecification
 */
class LocalisationLibarySpecification extends AeroSpec
{
	protected function initialize()
	{
		Aero::load('libs/i18n');
	}
	
	protected function beforeEach()
	{
		Aero::setOption('i18n.locale','en-gb');
	}
	
	protected function itShouldLocaliseDates()
	{
		$date_string = ae('tests','date','24 May 99');
		$this->string($date_string)->isSimilarTo('It happened on Monday, 24 May 1999.');
		
		$date_string = ae('tests','date_2','24 May 99');
		$this->string($date_string)->isSimilarTo('It happened in May 1999.');

	}
	
	protected function itShouldFallBackToParentLocales()
	{
		Aero::setOption('i18n.locale','en-us');
		
		$date_string = ae('tests','date','20 May 99');
		$this->string($date_string)->isSimilarTo('It happened on Thursday, 20 May 1999.');

	}

	protected function itShouldLocaliseDatesInRussian()
	{
		Aero::setOption('i18n.locale','ru-ru');
		
		$date_string = ae('tests','date','24 May 99');
		$this->string($date_string)->isSimilarTo('Это случилось в понедельник, 24-го мая 1999.');

		$date_string = ae('tests','date_2','24 May 99');
		$this->string($date_string)->isSimilarTo('Это случилось в мае 1999.');
	}
	
	protected function itShouldChooseCorrectPluralFormAndPrintNumericalStrings()
	{
		$string_0 = ae('tests','string',0);
		$string_1 = ae('tests','string',1);
		$string_4 = ae('tests','string',4);
		$string_101 = ae('tests','string',101);
		$string_1119 = ae('tests','string',1119);
		$string_1500 = ae('tests','string',1500);
		$string_15500 = ae('tests','string',15500);
		$string_1500500 = ae('tests','string',1500500);
		$string_high = ae('tests','string',8274129834712987);
		
		$this->string($string_0)->isSimilarTo('There are zero bananas on the table.');
		$this->string($string_1)->isSimilarTo('There is one banana on the table.');
		$this->string($string_4)->isSimilarTo('There are four bananas on the table.');
		$this->string($string_101)->isSimilarTo('There are one hundred and one bananas on the table.');
		$this->string($string_1119)->isSimilarTo('There are one thousand one hundred and nineteen bananas on the table.');
		$this->string($string_1500)->isSimilarTo('There are one thousand and five hundred bananas on the table.');
		$this->string($string_15500)->isSimilarTo('There are fifteen thousand and five hundred bananas on the table.');
		$this->string($string_1500500)->isSimilarTo('There are one million five hundred thousand and five hundred bananas on the table.');
		$this->string($string_high)->isSimilarTo('There are eight quadrillion two hundred seventy four trillion one hundred twenty nine billion eight hundred thirty four million seven hundred twelve thousand nine hundred and eighty seven bananas on the table.');
	}
	
	protected function itShouldChooseCorrectPluralFormAndPrintNumericalStringsInRussian()
	{
		Aero::setOption('i18n.locale','ru-ru');
		
		$string_1 = ae('tests','string',1);
		$string_4 = ae('tests','string',4);
		$string_101 = ae('tests','string',101);
		$string_1119 = ae('tests','string',1119);
		$string_1500 = ae('tests','string',1500);
		$string_15500 = ae('tests','string',15500);
		$string_1500500 = ae('tests','string',1500500);
		$string_high = ae('tests','string',8274129834712987);
		
		$this->string($string_1)->isSimilarTo('На столе лежит один банан.');
		$this->string($string_4)->isSimilarTo('На столе лежат четыре банана.');
		$this->string($string_101)->isSimilarTo('На столе лежит сто один банан.');
		$this->string($string_1119)->isSimilarTo('На столе лежат одна тысяча сто девятнадцать бананов.');
		$this->string($string_1500)->isSimilarTo('На столе лежат одна тысяча пятьсот бананов.');
		$this->string($string_15500)->isSimilarTo('На столе лежат пятнадцать тысяч пятьсот бананов.');
		$this->string($string_1500500)->isSimilarTo('На столе лежат один миллион пятьсот тысяч пятьсот бананов.');
		$this->string($string_high)->isSimilarTo('На столе лежат восемь квадриллионов двести семьдесят четыре триллиона сто двадцать девять миллиардов восемьсот тридцать четыре миллиона семьсот двенадцать тысяч девятьсот восемьдесят семь бананов.');
	}
}